import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Button {
    public static void main(String[] args) {
        JFrame frame=new JFrame("按钮");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(800,700);

        JTextField textField=new JTextField();
        textField.setEditable(false);
        frame.getContentPane().add(textField, BorderLayout.CENTER);

        JButton button1=new JButton("Button1");
        JButton button2=new JButton("Button2");

        JPanel buttonPanel=new JPanel();
        buttonPanel.add(button1);
        buttonPanel.add(button2);
        frame.getContentPane().add(buttonPanel,BorderLayout.NORTH);

        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                textField.setText(button1.getText());
            }
        });

        button2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                textField.setText(button2.getText());
            }
        });

        frame.setVisible(true);
    }

}
